package cn.wolfcode.shop.seckillserver.service.impl;

import cn.wolfcode.shop.seckillapi.domain.OrderInfo;
import cn.wolfcode.shop.seckillapi.service.IOrderInfoService;
import cn.wolfcode.shop.seckillapi.vo.SeckillOrderVO;
import cn.wolfcode.shop.seckillserver.mapper.OrderInfoMapper;
import cn.wolfcode.shop.seckillserver.util.IdGenerateUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.UUID;

@Service
public class OrderInfoServiceImpl implements IOrderInfoService {

    @Autowired
    private OrderInfoMapper orderInfoMapper;

    @Override
    public OrderInfo createOrderInfo(SeckillOrderVO seckillOrderVO, Long userId) {

        OrderInfo orderInfo = new OrderInfo();

        BeanUtils.copyProperties(seckillOrderVO,orderInfo);
        String orderNo = UUID.randomUUID().toString().replace("-", "");

        orderInfo.setOrderNo(IdGenerateUtil.get().nextId()+"");
        orderInfo.setUserId(userId);
        orderInfo.setGoodCount(1);
        orderInfo.setCreateDate(new Date());

        orderInfoMapper.save(orderInfo);

        return orderInfo;
    }
}
